package ygg.encoding.swf.tag.codec
{
	import j.sus2maj7.encoding.*;
	import j.sus2maj7.context.*;
	import flash.utils.ByteArray;
	
	import ygg.encoding.swf.tag.*;
	import ygg.encoding.swf.tag.object.*;
	
	public class DefineBitsJPEG3Codec extends TagCodec
	{
		public function DefineBitsJPEG3Codec()
		{
			super();
		}
		
		override public function decode(binary:IBinary, context:IContext=null):*
		{
			var retVal:DefineBitsJPEG3 = new DefineBitsJPEG3();
			var b:TagBinary = binary as TagBinary;
			b.position = 0;
			b.syncBits();
			
			retVal.characterId = b.readU16();
			retVal.alphaDataOffset = b.readUnsignedInt();// .readEncU32();
			
			var ba:ByteArray = new ByteArray();
			b.readBytes(ba, 0, retVal.alphaDataOffset);
			retVal.imageData = new TagBinary(ba);
			
			//check if jpeg, png, or gif89a
			var ba2:ByteArray = new ByteArray();
			b.readBytes(ba2);
			retVal.bitmapAlphaData = new TagBinary(ba2);
			
			return retVal;
		}
		
		override public function encode(o:*, context:IContext=null):IBinary
		{
			var b:TagBinary = new TagBinary();
			var obj:DefineBitsJPEG3 = o as DefineBitsJPEG3;
			
			
			
			return b;
		}
	}
}